<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <script src="../vue.js"></script>
  <style>
    .public {
      width: 100px;
      height: 100px;
    }

    .active {
      background-color: red;
    }

    .noActive {
      background-color: yellow;
    }

    .red {
      color: red;
    }

    .bold {
      font-weight: bold;
    }


    .italic {
      font-style: italic;
    }
  </style>
</head>

<body>
  <div id="app">
    <!-- 1.值为字符串,一般类名只有一个 -->
    <div class="public" :class="isActive?'active':'noActive'">box1</div>
    <div class="public" :class="fontColorClass">box2</div>

    <!-- 2.值为一个对象,对象的key都是需要的class名称,值是布尔值,通过布尔值来控制当前类是否使用 -->
    <div class="public" :class="box3Class">box3</div>
    <div class="public" :class="{red:isRed,bold:isBold,italic:isItalic}">box4</div>
  
    <!-- 3.值是一个数组,个数不固定,可以增删改 -->
    <div class="public" :class="classArr">box5</div>
  </div>
  <script>
    Vue.config.productionTip = false;

    const vm = new Vue({
      el: "#app",
      data() {
        return {
          isActive: true,
          fontColorClass: "red",
          box3Class: {
            red: true,
            bold: true,
            italic: true
          },
          isRed: true,
          isBold: true,
          isItalic: true,
          classArr : ['red','italic']
        }
      }
    })
  </script>
</body>

</html>